package domain;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;


public class StudentManager {

    public  static  void main(String[] args){
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
        Configuration configuration = new Configuration().configure();
        SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);

        Session session = sessionFactory.openSession();
        Transaction transaction = session.beginTransaction();

        Student student = new Student();
        student.setAge(18);
        student.setName("a");

        Address address1 = new Address("DC");

        student.setAddress(address1);
        session.persist(student);
        session.persist(address1);


//        Name name = new Name("fn","ln");
//        name.getPower().put("ak",1);
//        name.getPower().put("bk",2);
//        student.setName(name);
//        student.getSchools().add("中学");
//        student.getSchools().add("小学");
//        student.getTrainings().add("a");
//        student.getTrainings().add("c");

        transaction.commit();

        Student student1 = session.get(Student.class,1);
        System.out.println(student1);
//        System.out.println(student2.getName().getPower());
//        student2.getSchools().stream().forEach(System.out::println);
//        student2.getTrainings().stream().forEach(System.out::println);


        session.close();
        sessionFactory.close();
    }
}
